package com.yanqu.road.server.cmd.activity.washe;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.WasheProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.washe.WasheModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_WASHE_CHANGE_DECORATION,desc = "瓦舍改变装饰(棋盘,特效,结算动画等)")
public class WaSheChangeDecorationCmd extends AbstractCommand {

    private int type;

    private int decorationId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WasheProto.WasheChangeDecorationReqMsg reqMsg = WasheProto.WasheChangeDecorationReqMsg.parseFrom(packet.getBytes());
        type = reqMsg.getType();
        decorationId = reqMsg.getDecorationId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(WasheModule.class).changeDecoration(type,decorationId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            WasheProto.WasheChangeDecorationRespMsg.Builder respMsg = WasheProto.WasheChangeDecorationRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_WASHE_CHANGE_DECORATION,respMsg);
        }
    }
}
